/*
 * Copyright (c) 2025 Li Auto Inc. and its affiliates
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef INCLUDE_EDDS_RTPS_COMMON_E2E_COMMON_H_
#define INCLUDE_EDDS_RTPS_COMMON_E2E_COMMON_H_

#include <edds/rtps/common/all_common.h>
#include <cstdint>
#include <map>

namespace evbs {
namespace ertps {
namespace rtps {

using vbs::common::CacheChange_t;
class e2eCommon {
 public:
    e2eCommon();
    ~e2eCommon();

    typedef enum { READERID = 1, DATAID = 2 } AppIdType;

    static uint32_t calculateCRC32P4(uint32_t crc, const uint8_t* Crc_DataPtr, uint32_t Crc_Length, bool first = false);

    static uint32_t calculateCRC32P4(const uint8_t* Crc_DataPtr, uint32_t Crc_Length, const EntityId_t& reader_id,
                                     EntityId_t& writer_id, SequenceNumber_t seq);
    static void incrementCounter(uint16_t& counter);

    static unsigned int doCheckP04(const E2EProfile04_t& e2eHeader, CacheChange_t* change,
                                   SequenceNumber_t* expectedCounter, uint16_t e2e_P04MinDataLength,
                                   uint16_t e2e_P04MaxDataLength, uint16_t e2e_P04MaxDeltaCounter,
                                   bool& isNotFirstReceive);
    static uint32_t getAppId(uint32_t mode, const uint32_t readerId, const uint32_t dataId);
};

} /* namespace rtps */
} /* namespace ertps */
} /* namespace evbs */

#endif  // INCLUDE_EDDS_RTPS_COMMON_E2E_COMMON_H_
